package com.example.kugou.service.serviceimpl;

import com.example.kugou.mapper.AlbumMapper;
import com.example.kugou.mapper.MvMapper;
import com.example.kugou.mapper.SingMapper;
import com.example.kugou.mapper.SingerMapper;
import com.example.kugou.pojo.Album;
import com.example.kugou.pojo.Mv;
import com.example.kugou.pojo.Sing;
import com.example.kugou.pojo.Singer;
import com.example.kugou.service.SingerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("singerService")
public class SingerServiceImpl implements SingerService {

    @Resource
    SingerMapper singerMapper;

    @Resource
    SingMapper singMapper;
    @Resource
    AlbumMapper albumMapper;

    @Resource
    MvMapper mvMapper;

    public SingerMapper getSingerMapper() {
        return singerMapper;
    }

    public void setSingerMapper(SingerMapper singerMapper) {
        this.singerMapper = singerMapper;
    }

    @Override
    public Singer selectSingerId(int id) {
        Singer singer = singerMapper.selectSingerId(id);
        if (singer != null &&singer.getRid() > 0){
            List<Sing> sings = singMapper.selectSingBySingerId(id);
            if (sings != null && sings.size() > 0){
                singer.setSings(sings);
            }
            List<Album> albums = albumMapper.selectAlbumBySingerId(id);
            if (albums != null && albums.size() > 0){
                singer.setAlbum(albums);
            }
            List<Mv> mvs = mvMapper.selectMvBySingerId(id);
            if(mvs != null && mvs.size() > 0){
                singer.setMvs(mvs);
            }
        }
        return singer;
    }

    @Override
    public List<Singer> selectAllSinger(int typeId,String name) {
        return singerMapper.selectAllSinger(typeId,name);
    }

    @Override
    public List<Singer> selectBySwid(Integer swid) {
        return singerMapper.selectBySwid(swid);
    }

    @Override
    public int deleteByRid(Integer rid) {
        return singerMapper.deleteByRid(rid);
    }

    @Override
    public int updateSingerJianjie(String jianjie, Integer rid) {
        return singerMapper.updateSingerJianjie(jianjie,rid);
    }

    @Override
    public Singer selectByName(String name) {
        Singer singer = singerMapper.selectByName(name);
        return singer ;
    }

    @Override
    public List<Singer> selectName(String name) {
        return singerMapper.selectName(name);
    }

    @Override
    public int insertSinger(Singer singer) {
        return singerMapper.insertSinger(singer);
    }
}
